/**
 * Created by Administrator on 2017/4/11 0011.
 */
var Choose={
    create:function () {
        var page={};
        page.ui=new PIXI.DisplayObjectContainer();

        var con_scroll=new PIXI.DisplayObjectContainer();
        page.ui.addChild(con_scroll);

        var sp_bottom=Easy.CreateSprite('assets/images/choose_plane.png',370,1011,0.5,0.5,0);
        page.ui.addChild(sp_bottom);

        var sp_line0=Easy.CreateSprite('assets/images/choose_line.png',246,1034,0.5,0.5,0);
        page.ui.addChild(sp_line0);
        var sp_line1=Easy.CreateSprite('assets/images/choose_line.png',491,1034,0.5,0.5,0);
        page.ui.addChild(sp_line1);

        var bt_0=Easy.CreateSprite('assets/images/choose_bt0.png',146,982,0.5,0.5,1);
        bt_0.name='0';
        bt_0.interactive=false;
        bt_0.on('pointerdown',downHandler);
        page.ui.addChild(bt_0);
        var bt_1=Easy.CreateSprite('assets/images/choose_bt1.png',370,982,0.5,0.5,1);
        bt_1.name='1';
        bt_1.interactive=false;
        bt_1.on('pointerdown',downHandler);
        page.ui.addChild(bt_1);
        var bt_2=Easy.CreateSprite('assets/images/choose_bt2.png',594,982,0.5,0.5,1);
        bt_2.name='2';
        bt_2.interactive=false;
        bt_2.on('pointerdown',downHandler);
        page.ui.addChild(bt_2);
        var bt_3=Easy.CreateSprite('assets/images/choose_bt3.png',141,1084,0.5,0.5,1);
        bt_3.name='3';
        bt_3.interactive=false;
        bt_3.on('pointerdown',downHandler);
        page.ui.addChild(bt_3);
        var bt_4=Easy.CreateSprite('assets/images/choose_bt4.png',373,1083,0.5,0.5,1);
        bt_4.name='4';
        bt_4.interactive=false;
        bt_4.on('pointerdown',downHandler);
        page.ui.addChild(bt_4);
        var bt_5=Easy.CreateSprite('assets/images/choose_bt5.png',595,1083,0.5,0.5,1);
        bt_5.name='5';
        bt_5.interactive=false;
        bt_5.on('pointerdown',downHandler);
        page.ui.addChild(bt_5);

        bt_0.interactive=true;
        bt_1.interactive=true;
        bt_2.interactive=true;
        bt_3.interactive=true;
        bt_4.interactive=true;
        bt_5.interactive=true;


        var sp_i0=Easy.CreateSprite('assets/images/choose_i0.png',0,0,0,0,1);
        TweenMax.to(sp_i0,60,{x:-sp_i0.width+740,repeat:-1,yoyo:true,repeatDelay:1,ease:Linear.easeNone});
        con_scroll.addChild(sp_i0);
        var i0_mask=new PIXI.Graphics();
        i0_mask.beginFill(0x0,1);
        i0_mask.drawRect(0,0,740,1136);
        i0_mask.endFill();
        i0_mask.x=740*0;
        con_scroll.addChild(i0_mask);
        sp_i0.mask=i0_mask;

        var sp_i1=Easy.CreateSprite('assets/images/choose_i1.png',740*1,0,0,0,1);
        TweenMax.to(sp_i1,60,{x:740-sp_i1.width+740,repeat:-1,yoyo:true,repeatDelay:1,ease:Linear.easeNone});
        con_scroll.addChild(sp_i1);
        var i1_mask=new PIXI.Graphics();
        i1_mask.beginFill(0x0,1);
        i1_mask.drawRect(0,0,740,1136);
        i1_mask.endFill();
        i1_mask.x=740*1;
        con_scroll.addChild(i1_mask);
        sp_i1.mask=i1_mask;

        var sp_i2=Easy.CreateSprite('assets/images/choose_i2.png',740*2,0,0,0,1);
        TweenMax.to(sp_i2,60,{x:740*2-sp_i0.width+740,repeat:-1,yoyo:true,repeatDelay:1,ease:Linear.easeNone});
        con_scroll.addChild(sp_i2);
        var i2_mask=new PIXI.Graphics();
        i2_mask.beginFill(0x0,1);
        i2_mask.drawRect(0,0,740,1136);
        i2_mask.endFill();
        i2_mask.x=740*2;
        con_scroll.addChild(i2_mask);
        sp_i2.mask=i2_mask;

        var sp_dotBG=Easy.CreateSprite('assets/images/choose_dotBG.png',377,880,0.5,0.5,0);
        page.ui.addChild(sp_dotBG);
        var sp_dot=Easy.CreateSprite('assets/images/choose_dot.png',354,880,0.5,0.5,0);
        page.ui.addChild(sp_dot);

        var sc=Scroller.create(con_scroll,pixiStageW,pixiStageH,'hor',2,'Choose',[]);
        document.addEventListener(sc.name+'Game_ScrollStart',function(e)
        {

        });
        document.addEventListener(sc.name+'Game_ScrollComplete',function(e)
        {
            sp_dot.x=354+Math.floor(e.detail)*23;
        });


        // var sp_i1=Easy.CreateSprite('assets/images/choose_i1.png',0,0,0,0,1);
        // con_scroll.addChild(sp_i1);
        // var sp_i2=Easy.CreateSprite('assets/images/choose_i2.png',0,0,0,0,1);
        // con_scroll.addChild(sp_i2);
            
        page.In=function () {

            setTimeout(function () {
                con_scroll.interactive=true;
            },1000);

            bt_0.interactive=true;
            bt_1.interactive=true;
            bt_2.interactive=true;
            bt_3.interactive=true;
            bt_4.interactive=true;
            bt_5.interactive=true;

            con_scroll.y=1136;
            con_scroll.alpha=0;
            TweenMax.to(con_scroll,1.5,{alpha:1,y:0,ease:Cubic.easeInOut});

            sp_bottom.alpha=0;
            sp_bottom.y=1011+300;
            TweenMax.to(sp_bottom,1.5,{alpha:1,y:1030,ease:Cubic.easeInOut});

            sp_line0.scale.x=sp_line0.scale.y=0;
            sp_line0.alpha=0;
            TweenMax.to(sp_line0,1,{delay:1.0,alpha:1,ease:Back.easeOut});
            TweenMax.to(sp_line0.scale,1,{delay:1.0,x:1,y:1,ease:Back.easeOut});
            sp_line1.scale.x=sp_line1.scale.y=0;
            sp_line1.alpha=0;
            TweenMax.to(sp_line1,1,{delay:1.0,alpha:1,ease:Back.easeOut});
            TweenMax.to(sp_line1.scale,1,{delay:1.0,x:1,y:1,ease:Back.easeOut});

            sp_dotBG.alpha=0;
            sp_dot.alpha=0;
            TweenMax.to(sp_dotBG,1,{delay:2.0,alpha:1});
            TweenMax.to(sp_dot,1,{delay:2.0,alpha:1});


            bt_0.scale.x=bt_0.scale.y=0;
            bt_1.scale.x=bt_1.scale.y=0;
            bt_2.scale.x=bt_2.scale.y=0;
            bt_3.scale.x=bt_3.scale.y=0;
            bt_4.scale.x=bt_4.scale.y=0;
            bt_5.scale.x=bt_5.scale.y=0;
            TweenMax.to(bt_0.scale,1,{delay:1.2+0.2*0,x:1,y:1,ease:Back.easeOut});
            TweenMax.to(bt_1.scale,1,{delay:1.2+0.2*1,x:1,y:1,ease:Back.easeOut});
            TweenMax.to(bt_2.scale,1,{delay:1.2+0.2*2,x:1,y:1,ease:Back.easeOut});
            TweenMax.to(bt_3.scale,1,{delay:1.2+0.2*3,x:1,y:1,ease:Back.easeOut});
            TweenMax.to(bt_4.scale,1,{delay:1.2+0.2*4,x:1,y:1,ease:Back.easeOut});
            TweenMax.to(bt_5.scale,1,{delay:1.2+0.2*5,x:1,y:1,ease:Back.easeOut});
        }
        page.Out=function () {
            
        }
        
        function downHandler(e)
        {
            bt_0.interactive=false;
            bt_1.interactive=false;
            bt_2.interactive=false;
            bt_3.interactive=false;
            bt_4.interactive=false;
            bt_5.interactive=false;
            con_scroll.interactive=false;

            var arr=[];
            var idx=e.currentTarget.name;
            arr.push('pageGame');
            arr.push(idx);
            document.dispatchEvent(new CustomEvent('Game_PageIn',{detail:arr}))
        }


        return page;
    }
}